﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//Please add references
namespace DAL
{
	/// <summary>
	/// 数据访问类:T_BaseExamSubjectRule
	/// </summary>
	public partial class T_BaseExamSubjectRule
	{
		public T_BaseExamSubjectRule()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Model.T_BaseExamSubjectRule model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_BaseExamSubjectRule(");
			strSql.Append("ExamId,TypeCode,CountTote,CountValue,GroupId,GroupName)");
			strSql.Append(" values (");
			strSql.Append("@ExamId,@TypeCode,@CountTote,@CountValue,@GroupId,@GroupName)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamId", SqlDbType.Int,4),
					new SqlParameter("@TypeCode", SqlDbType.Float,8),
					new SqlParameter("@CountTote", SqlDbType.Float,8),
					new SqlParameter("@CountValue", SqlDbType.Float,8),
					new SqlParameter("@GroupId", SqlDbType.Float,8),
					new SqlParameter("@GroupName", SqlDbType.NVarChar,50)};
			parameters[0].Value = model.ExamId;
			parameters[1].Value = model.TypeCode;
			parameters[2].Value = model.CountTote;
			parameters[3].Value = model.CountValue;
			parameters[4].Value = model.GroupId;
			parameters[5].Value = model.GroupName;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Model.T_BaseExamSubjectRule model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_BaseExamSubjectRule set ");
			strSql.Append("ExamId=@ExamId,");
			strSql.Append("TypeCode=@TypeCode,");
			strSql.Append("CountTote=@CountTote,");
			strSql.Append("CountValue=@CountValue,");
			strSql.Append("GroupId=@GroupId,");
			strSql.Append("GroupName=@GroupName");
			strSql.Append(" where ExamSubjectRuleId=@ExamSubjectRuleId");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamId", SqlDbType.Int,4),
					new SqlParameter("@TypeCode", SqlDbType.Float,8),
					new SqlParameter("@CountTote", SqlDbType.Float,8),
					new SqlParameter("@CountValue", SqlDbType.Float,8),
					new SqlParameter("@GroupId", SqlDbType.Float,8),
					new SqlParameter("@GroupName", SqlDbType.NVarChar,50),
					new SqlParameter("@ExamSubjectRuleId", SqlDbType.Int,4)};
			parameters[0].Value = model.ExamId;
			parameters[1].Value = model.TypeCode;
			parameters[2].Value = model.CountTote;
			parameters[3].Value = model.CountValue;
			parameters[4].Value = model.GroupId;
			parameters[5].Value = model.GroupName;
			parameters[6].Value = model.ExamSubjectRuleId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ExamSubjectRuleId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_BaseExamSubjectRule ");
			strSql.Append(" where ExamSubjectRuleId=@ExamSubjectRuleId");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamSubjectRuleId", SqlDbType.Int,4)
			};
			parameters[0].Value = ExamSubjectRuleId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string ExamSubjectRuleIdlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_BaseExamSubjectRule ");
			strSql.Append(" where ExamSubjectRuleId in ("+ExamSubjectRuleIdlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_BaseExamSubjectRule GetModel(int ExamSubjectRuleId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ExamSubjectRuleId,ExamId,TypeCode,CountTote,CountValue,GroupId,GroupName from T_BaseExamSubjectRule ");
			strSql.Append(" where ExamSubjectRuleId=@ExamSubjectRuleId");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamSubjectRuleId", SqlDbType.Int,4)
			};
			parameters[0].Value = ExamSubjectRuleId;

			Model.T_BaseExamSubjectRule model=new Model.T_BaseExamSubjectRule();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_BaseExamSubjectRule DataRowToModel(DataRow row)
		{
			Model.T_BaseExamSubjectRule model=new Model.T_BaseExamSubjectRule();
			if (row != null)
			{
				if(row["ExamSubjectRuleId"]!=null && row["ExamSubjectRuleId"].ToString()!="")
				{
					model.ExamSubjectRuleId=int.Parse(row["ExamSubjectRuleId"].ToString());
				}
				if(row["ExamId"]!=null && row["ExamId"].ToString()!="")
				{
					model.ExamId=int.Parse(row["ExamId"].ToString());
				}
				if(row["TypeCode"]!=null && row["TypeCode"].ToString()!="")
				{
					model.TypeCode=decimal.Parse(row["TypeCode"].ToString());
				}
				if(row["CountTote"]!=null && row["CountTote"].ToString()!="")
				{
					model.CountTote=decimal.Parse(row["CountTote"].ToString());
				}
				if(row["CountValue"]!=null && row["CountValue"].ToString()!="")
				{
					model.CountValue=decimal.Parse(row["CountValue"].ToString());
				}
				if(row["GroupId"]!=null && row["GroupId"].ToString()!="")
				{
					model.GroupId=decimal.Parse(row["GroupId"].ToString());
				}
				if(row["GroupName"]!=null)
				{
					model.GroupName=row["GroupName"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ExamSubjectRuleId,ExamId,TypeCode,CountTote,CountValue,GroupId,GroupName ");
			strSql.Append(" FROM T_BaseExamSubjectRule ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ExamSubjectRuleId,ExamId,TypeCode,CountTote,CountValue,GroupId,GroupName ");
			strSql.Append(" FROM T_BaseExamSubjectRule ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_BaseExamSubjectRule ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ExamSubjectRuleId desc");
			}
			strSql.Append(")AS Row, T.*  from T_BaseExamSubjectRule T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_BaseExamSubjectRule";
			parameters[1].Value = "ExamSubjectRuleId";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

